package org.paradise.dms.services.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.paradise.dms.dao.impl.MainReportDAOImpl;
import org.paradise.dms.pojo.MaintainReport;
import org.paradise.dms.services.MainReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.dheaven.framework.dao.DaoException;

/**
 * 
 * Description: MaintainReport Service类 Copyright (c) 2008-2009 Neo. All Rights
 * Reserved.
 * 
 * @version 1.0 Mar 19, 2009 9:35:24 AM 李萌（neolimeng@gmail.com）created
 */

@Service
public class MainReportServiceImpl implements MainReportService {
	private static Logger log = Logger.getLogger(MainReportServiceImpl.class);

	@Autowired
	@Qualifier("mainReportDAOImpl")
	private MainReportDAOImpl mainReportDAOImpl;
	List<MaintainReport> lmr;
	MaintainReport mr;

	public MainReportDAOImpl getMainReportDAOImpl() {
		return mainReportDAOImpl;
	}

	public void setMainReportDAOImpl(MainReportDAOImpl mainReportDAOImpl) {
		this.mainReportDAOImpl = mainReportDAOImpl;
	}

	public boolean deleteMainReport(int maintainreportid) {
		if (this.mainReportDAOImpl
				.deleteMaintainReportByMaintainreportid(maintainreportid)) {
			log.info("DMS_info_删除报修记录，成功！！ID为：" + maintainreportid);
			return true;
		} else {
			log.error("DMS_error_删除报修记录，失败！！ID为：" + maintainreportid);
			return false;
		}
	}

	public List<MaintainReport> findAllMainReports() throws DaoException {
		try {
			lmr = this.mainReportDAOImpl.getMaintainReports();
			log.info("DMS_info_取得所有报修记录，成功！！共有：" + lmr.size() + "条。");
			return lmr;
		} catch (Exception e) {
			log.error("DMS_error_取得所有报修记录，失败！！");
			e.printStackTrace();
			return null;
		}
	}

	public List<MaintainReport> findMainReport(int maintainreportid)
			throws DaoException {
		try {
			lmr = this.mainReportDAOImpl.getMaintainReport(maintainreportid);
			log.info("DMS_info_根据ID取得报修记录，成功！！ID为：" + maintainreportid);
			return lmr;
		} catch (Exception e) {
			log.error("DMS_error_根据ID取得报修记录，失败！！ID为：" + maintainreportid);
			e.printStackTrace();
			return null;
		}
	}

	public boolean insertMainReport(MaintainReport maintainreport) {
		if (this.mainReportDAOImpl.insertMaintainReport(maintainreport)) {
			log.info("DMS_info_插入报修记录，成功！！学号："
					+ maintainreport.getMaintainreporter());
			return true;
		} else {
			log.error("DMS_error_插入报修记录，失败！！");
			return false;
		}
	}

	public boolean updateMainReport(MaintainReport maintainreport) {
		if (this.mainReportDAOImpl.updateMaintainReport(maintainreport)) {
			log.info("DMS_info_更新报修记录，成功！！ID值："
					+ maintainreport.getMaintainreportid());
			return true;
		} else {
			log.error("DMS_error_更新报修记录，失败！！ID值："
					+ maintainreport.getMaintainreportid());
			return false;
		}
	}

	public boolean setFinished(int mrid) {
		try {
			this.mainReportDAOImpl.setFinished(mrid);
			log.info("DMS_info_设置维修完成，成功！！ID值为：" + mrid);
			return true;
		} catch (Exception e) {
			log.error("DMS_error_设置维修完成，失败！！ID值为：" + mrid);
			e.printStackTrace();
			return false;
		}
	}

	public int getAllRows() {
		return this.mainReportDAOImpl.getAllRows();
	}

	public List<MaintainReport> listAllMaintainReports(int pageSize,
			int startRow) {
		try {
			lmr = this.mainReportDAOImpl.listAllMaintainReport(pageSize,
					startRow);
			log.info("DMS_info_分页取得所有报修记录，成功！！本次读取" + pageSize + "条，起始条为第"
					+ startRow + "条");
			return lmr;
		} catch (Exception e) {
			log.error("DMS_error_分页取得所有报修记录，失败！！");
			e.printStackTrace();
			return null;
		}
	}

	public List<MaintainReport> getLmr() {
		return lmr;
	}

	public void setLmr(List<MaintainReport> lmr) {
		this.lmr = lmr;
	}

	public MaintainReport getMr() {
		return mr;
	}

	public void setMr(MaintainReport mr) {
		this.mr = mr;
	}

}
